package icu.javayanglei.bilibili.domain;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 弹幕
 *
 * @TableName dm
 */
@TableName(value = "dm")
@Builder
@Data
@AllArgsConstructor
@NoArgsConstructor
@Slf4j
@Accessors(chain = true)
public class Dm implements Serializable {
    @TableField(exist = false)
    private static final long serialVersionUID = 1L;
    /**
     *
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;
    /**
     * dm id
     */
    @TableField(value = "dm_id")
    private Long dmId;
    /**
     * 弹幕正文，utf8
     */
    @TableField(value = "content")
    private String content;
    /**
     * 创建时间戳
     */
    @TableField(value = "c_time")
    private LocalDateTime cTime;
    /**
     * 用户 id
     */
    @TableField(value = "mid")
    private String mid;
    /**
     * 发送者mid的HASH，用于屏蔽用户和查看用户发送的所有弹幕 也可反查用户id
     */
    @TableField(value = "midHash")
    private String midhash;

    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        Dm other = (Dm) that;
        return (this.getId() == null ? other.getId() == null : this.getId().equals(other.getId()))
                && (this.getDmId() == null ? other.getDmId() == null : this.getDmId().equals(other.getDmId()))
                && (this.getContent() == null ? other.getContent() == null : this.getContent().equals(other.getContent()))
                && (this.getCTime() == null ? other.getCTime() == null : this.getCTime().equals(other.getCTime()))
                && (this.getMid() == null ? other.getMid() == null : this.getMid().equals(other.getMid()))
                && (this.getMidhash() == null ? other.getMidhash() == null : this.getMidhash().equals(other.getMidhash()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getId() == null) ? 0 : getId().hashCode());
        result = prime * result + ((getDmId() == null) ? 0 : getDmId().hashCode());
        result = prime * result + ((getContent() == null) ? 0 : getContent().hashCode());
        result = prime * result + ((getCTime() == null) ? 0 : getCTime().hashCode());
        result = prime * result + ((getMid() == null) ? 0 : getMid().hashCode());
        result = prime * result + ((getMidhash() == null) ? 0 : getMidhash().hashCode());
        return result;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append(getClass().getSimpleName());
        sb.append(" [");
        sb.append("Hash = ").append(hashCode());
        sb.append(", id=").append(id);
        sb.append(", dmId=").append(dmId);
        sb.append(", content=").append(content);
        sb.append(", cTime=").append(cTime);
        sb.append(", mid=").append(mid);
        sb.append(", midhash=").append(midhash);
        sb.append(", serialVersionUID=").append(serialVersionUID);
        sb.append("]");
        return sb.toString();
    }
}
